<?php
    echo doctype();
?>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>
            <?php
                echo $this->lang->line('manager_title_stats');
            ?>
        </title>
        <?php
            echo link_tag('css/global.css');
            echo link_tag('css/manager.css');
        ?>
    </head>
    <body>
        <div id="container">
            <div id="leftcon">
                <div id="logo"></div>
                <div id="mngr_navi">
                    <ul>
                        <li>
                            <?php
                                echo anchor('manager/', $this->lang->line('manager_todays_statistics'));
                            ?>
                        </li>
                        <li>
                            <?php
                                echo anchor('manager/agents_grid', $this->lang->line('manager_manage_agents'));
                            ?>
                        </li>
                        <li>
                            <?php
                                echo anchor('manager/unit', 'Unit');
                            ?>
                        </li>
                        <li>
                            <?php
                                echo anchor('manager/deactivate', $this->lang->line('manager_deactivate'));
                            ?>
                        </li>
                        <li>
                            <?php
                                echo anchor('logout/', $this->lang->line('manager_logout'));
                            ?>
                        </li>
                    </ul>
                </div>
            </div>
            <div id="content">
                <div id="mngr_content">
                    <h1>
                        <?php
                            echo $this->lang->line('manager_todays_statistics');
                        ?>
                    </h1>
                    <div id="stat_flexigrid">

                        <h2>
                            <?php
                                echo $this->lang->line('manager_ticketed_service');
                            ?>
                        </h2>
                        <table class="stat_table">
                            <tr>
                                <th class="th_head">
                                    <?php
                                        echo $this->lang->line('manager_service');
                                    ?>
                                </th>
                                <th class="th_head">
                                    <?php
                                        echo $this->lang->line('manager_queue');
                                    ?>
                                </th>
                                <th class="th_head">
                                    <?php
                                        echo $this->lang->line('manager_served');
                                    ?>
                                </th>
                                <th class="th_head">
                                    <?php
                                        echo $this->lang->line('manager_missed');
                                    ?>
                                </th>
                                <th class="th_head">
                                    <?php
                                        echo $this->lang->line('manager_total');
                                    ?>
                                </th>
                                <th class="th_head">
                                    <?php
                                        echo $this->lang->line('manager_percentage');
                                    ?>
                                </th>
                                <th class="th_head">
                                    <?php
                                        echo $this->lang->line('manager_handling_time');
                                    ?>
                                </th>
                            </tr>
                            <?php
                                $overall_service_total = $services_stat['total_waiting'] + $services_stat['total_served'] + $services_stat['total_missed'];
                                for($i = 0; $i < count($services_stat['individual']); $i++)
                                {
                            ?>
                            <tr>
                                <th class="left">
                                    <?php
                                        echo $services_stat['individual'][$i]['title'];
                                    ?>
                                </th>
                                <td>
                                    <?php
                                        echo $services_stat['individual'][$i]['waiting'];
                                    ?>
                                </td>
                                <td>
                                    <?php
                                        echo $services_stat['individual'][$i]['served'];
                                    ?>
                                </td>
                                <td>
                                    <?php
                                        echo $services_stat['individual'][$i]['missed'];
                                    ?>
                                </td>
                                <td>
                                    <?php
                                        $service_total = $services_stat['individual'][$i]['waiting'] + $services_stat['individual'][$i]['served'] + $services_stat['individual'][$i]['missed'];
                                        echo $service_total;
                                    ?>
                                </td>
                                <td>
                                    <?php
                                        echo sprintf('%.2f', $service_total / ($overall_service_total == 0 ? 1 : $overall_service_total) * 100);
                                        echo '%';
                                    ?>
                                </td>

                                <td class="center">
                                    <?php
                                        echo ($services_stat['individual'][$i]['processing_time'] > 0 ? mdate('%H:%i:%s', $services_stat['individual'][$i]['processing_time']) : '00:00:00');
                                    ?>
                                </td>
                            </tr>
                            <?php
                                }
                            ?>
                            <tr>
                                <th class="totalc">
                                    <?php
                                        echo 'Total';
                                    ?>
                                </th>
                                <th class="total">
                                    <?php
                                        echo $services_stat['total_waiting'];
                                    ?>
                                </th>
                                <th class="total">
                                    <?php
                                        echo $services_stat['total_served'];
                                    ?>
                                </th>
                                <th class="total">
                                    <?php
                                        echo $services_stat['total_missed'];
                                    ?>
                                </th>
                                <th class="total">
                                    <?php
                                        echo $overall_service_total;
                                    ?>
                                </th>
                                <th class="total">
                                    <?php
                                        echo  $overall_service_total == 0 ? '0.00%' : '100.00%';
                                    ?>
                                </th>
                                <th class="center">
                                    <?php
                                        echo ($services_stat['total_protime'] > 0 ? mdate('%H:%i:%s', $services_stat['total_protime']) : '00:00:00');
                                    ?>
                                </th>
                            </tr>
                        </table>
                        <h2>
                            <?php
                                echo 'Agent Statistics';
                            ?>
                        </h2>
                        <table class="stat_table">
                            <tr>
                                <th class="th_head">
                                    <?php
                                        echo $this->lang->line('manager_agent');
                                    ?>
                                </th>
                                <th class="th_head">
                                    <?php
                                        echo $this->lang->line('manager_served');
                                    ?>
                                </th>
                                <th class="th_head">
                                    <?php
                                        echo $this->lang->line('manager_missed');
                                    ?>
                                </th>
                                <th class="th_head">
                                    <?php
                                        echo $this->lang->line('manager_ave_time');
                                    ?>
                                </th>
                            </tr>
                            <?php
                                for($i = 0; $i < count($agents_stat['individual']); $i++)
                                {
                            ?>
                            <tr>
                                <th class="left">
                                    <?php
                                        echo $agents_stat['individual'][$i]['name'];
                                    ?>
                                </th>
                                <td>
                                    <?php
                                        echo $agents_stat['individual'][$i]['served'];
                                    ?>
                                </td>
                                <td>
                                    <?php
                                        echo $agents_stat['individual'][$i]['missed'];
                                    ?>
                                </td>
                                <td class="center">
                                    <?php
                                        echo $agents_stat['individual'][$i]['processing_time'] > 0 ? mdate('%H:%i:%s', $agents_stat['individual'][$i]['processing_time']) : '00:00:00';
                                    ?>
                                </td>
                            </tr>
                            <?php
                                }
                            ?>
                            <tr>
                                <th class="totalc">
                                    <?php
                                        echo 'Total';
                                    ?>
                                </th>
                                <th class="total">
                                    <?php
                                        echo $agents_stat['total_served'];
                                    ?>
                                </th>
                                <th class="total">
                                    <?php
                                        echo $agents_stat['total_missed'];
                                    ?>
                                </th>
                                <th>
                                    <?php
                                        echo $agents_stat['total_protime'] > 0 ? mdate('%H:%i:%s', $agents_stat['total_protime']) : '00:00:00';
                                    ?>
                                </th>
                            </tr>
                        </table>
                        <h2>
                            <?php
                                echo 'Service Statistics';
                            ?>
                        </h2>
                        <?php
                            for($i = 0; $i < count($services_stat['individual']); $i++)
                            {
                        ?>
                        <h3>
                            <?php
                                echo $services_stat['individual'][$i]['title'];
                            ?>
                        </h3>
                        <table class="stat_table">
                            <tr>
                                <th class="th_head">
                                    Closing Code
                                </th>
                                <th class="th_head">
                                    Frequency
                                </th>
                                <th class="th_head">
                                    Percentage
                                </th>
                            </tr>
                            <?php
                                $total_index = count($services_stat['individual'][$i]['closing_codes']) - 1;
                                $frequency_total = $services_stat['individual'][$i]['closing_codes'][$total_index]['frequency'];
                                for($a = 0; $a < $total_index; $a++)
                                {
                            ?>
                            <tr>
                                <th class="left">
                                    <?php
                                        echo $services_stat['individual'][$i]['closing_codes'][$a]['name'];
                                    ?>
                                </th>
                                <td>
                                    <?php
                                        echo $services_stat['individual'][$i]['closing_codes'][$a]['frequency'];
                                    ?>
                                </td>
                                <td>
                                    <?php
                                        echo sprintf('%0.2f', $services_stat['individual'][$i]['closing_codes'][$a]['frequency'] / ($frequency_total == 0 ? 1 : $frequency_total) * 100);
                                        echo '%';
                                    ?>
                                </td>
                            </tr>
                            <?php
                                }
                            ?>
                            <tr>
                                <th class="totalc">
                                    Total
                                </th>
                                <th class="total">
                                    <?php
                                        echo $services_stat['individual'][$i]['closing_codes'][$total_index]['frequency'];
                                    ?>
                                </th>
                                <th class="total">
                                    <?php
                                        echo $services_stat['individual'][$i]['closing_codes'][$total_index]['frequency'] == 0 ? '0.00%' : '100.00%';
                                    ?>
                                </th>
                            </tr>
                        </table>
                        <?php
                            }
                        ?>
                    </div>
                </div>
                <div id="footer">
                    <?php
                        echo $this->lang->line('global_copy_right');
                    ?>
                </div>
            </div>
        </div>
    </body>
</html>